package com.kankan.controller;

import com.kankan.common.ResponseEntity;
import com.kankan.service.SmsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("sms")
@Slf4j
public class SmsController {

    @Autowired
    SmsService smsService;

    @PostMapping("sendSms")
    public ResponseEntity<Object> sendSms(@RequestBody Map<String,String> params){
        //获取手机号
        String mobile = params.get("mobile");

        Boolean flag = smsService.sendMsg(mobile);

        if (flag){
           return ResponseEntity.builder().code("200").msg("success").build();
        }else {
            return ResponseEntity.builder().code("999").msg("fail").build();
        }
    }

}
